pacman::p_load(tidyverse, rjson, data.table, gghalves, plotly, gganimate, av, colorspace)
`%!in%` = Negate(`%in%`)
n of point searned vs. expected points (better than chance)
criteria: - points are representative to average - gem not found before round 10 - exploration is conistent
points_when_gem_found <- explore_data %>%
group_by(player, gempresent, tot_points, env_number) %>%
filter(gempresent == 1 & sum(gem) > 1) %>%
select(player, gempresent, tot_points, unique_rounds, env_number) %>%
distinct() %>%
ungroup() %>%
group_by(env_number) %>%
mutate(performance_group = ntile(tot_points, 3))
# distribution of point when gem is found
points_when_gem_found %>%
ggplot() +
geom_histogram(aes( x = tot_points, fill = factor(performance_group)), binwidth = 40)+
#, color = "white") +
#geom_vline(aes(xintercept = mean(tot_points)), lty = 2, size = 1, color = 'black') +
#geom_half_point(aes(x = factor(gempresent), y = points), alpha = 0.02) +
#theme_bw(base_size = 20) +
facet_wrap(~env_number)
guides(fill = "none")
## $fill
## [1] "none"
##
## attr(,"class")
## [1] "guides"
now filter for gem not found before round 10
# list of players
avg_rounds <- points_when_gem_found %>%
filter(performance_group == 2 | performance_group == 1) %>%
ungroup() %>%
select(unique_rounds)
avg_rounds <- avg_rounds$unique_rounds
early_gems_idx <- which(explore_data$gem & explore_data$trial <= 5)
round_to_exclude <- unique(explore_data$unique_rounds[early_gems_idx])
late_gems <- explore_data %>%
filter(unique_rounds %in% avg_rounds)%>%
filter(unique_rounds %!in% round_to_exclude)
how_may_late_gems <- late_gems%>%
group_by(env_number) %>%
summarise(sum = n())
make this into shiny app
gems_coords <- explore_data %>%
filter( points >160) %>%
select(x , y, env_number, round) %>%
filter(player == 42 & round == 2) %>%
distinct()
## Adding missing grouping variables: `player`
one_sequence <- late_gems %>%
filter(player == 42 & round == 2) %>%
ggplot() +
#geom_bin_2d(aes(x = x, y = y, fill = gem), binwidth = c(1, 1)) +
geom_rect(
data = gems_coords,
size = 1,
colour = "red",
fill = "white",
aes(
xmin = x - 1,
xmax = x ,
ymin = y - 1,
ymax = y
)
) +
geom_rect(aes(
xmin = x - 1,
xmax = x ,
ymin = y - 1,
ymax = y,
fill = points,
frame = trial
),
color = "black",
size = .2) +
scale_x_continuous(limits = c(-1, 7), breaks = -1:7) +
scale_y_continuous(limits = c(-1, 7), breaks = -1:7) +
scale_fill_continuous_divergingx(palette = "RdBu", mid = 0)
## Warning: Ignoring unknown aesthetics: frame
ggplotly(one_sequence) %>%
animation_opts( transition = 0)